﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ADOWrapper.ObjectResolver
{
    public class ObjectPopulator<T>
    {
        private static object locker = new object();
        public static IObjectPopulator<T> Get()
        {
            if (CustomPopulator != null)
                return CustomPopulator;

            if (resolvedPopulator == null)
            {
                lock (locker)
                {
                    if (typeof(T).FullName.StartsWith("System.Tuple`"))
                        resolvedPopulator = new TuplePopulator<T>();
                    else
                        resolvedPopulator = new GenericPopulator<T>();
                }
            }
            return resolvedPopulator;
        }

        private static IObjectPopulator<T> resolvedPopulator;

        /// <summary>
        /// Gets or sets custom object populator for T type
        /// </summary>       

        public static IObjectPopulator<T> CustomPopulator { get; set; }
    }
}
